package com.xtool.livewallpaper

import android.app.WallpaperManager
import android.content.res.Configuration
import android.os.Bundle
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import com.gyf.immersionbar.ImmersionBar
import com.xtool.livewallpaper.base.BaseActivity
import com.xtool.livewallpaper.base.PrefsHelper
import com.xtool.livewallpaper.databinding.ActivitySettingBinding
import com.xtool.livewallpaper.util.SystemRouterUtil
import com.xtool.livewallpaper.util.ToastUtil

class SettingActivity : BaseActivity() {
    private val binding: ActivitySettingBinding by lazy {
        ActivitySettingBinding.inflate(
            layoutInflater
        )
    }

    override fun onStart() {
        super.onStart()
        val uiMode = resources.configuration.uiMode
        val isNightMode = AppCompatDelegate.getDefaultNightMode() == MODE_NIGHT_YES
                || uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
        ImmersionBar.with(this)
            .statusBarDarkFont(!isNightMode)
            .transparentStatusBar()
            .init()
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        binding.scAutoBoot.isChecked = PrefsHelper.isAutoBoot
        binding.scAutoBoot.setOnCheckedChangeListener { buttonView, isChecked ->
            PrefsHelper.isAutoBoot = isChecked
        }
        binding.ivBack.setOnClickListener { finish() }
        binding.btnResetWallpaper.setOnClickListener {
            val wallpaperManager = WallpaperManager.getInstance(this)
            wallpaperManager.clear()
            ToastUtil.show(R.string.reset_wallpaper_success)
            SystemRouterUtil.goHome()
        }
    }

    override fun finish() {
        super.finish()
        overridePendingTransition(
            0,
            R.anim.activity_right_out
        )
    }
}